package p700;

public class Leetcode_704 {
    public int search(int[] nums, int target) {
        int left = 0, right = nums.length - 1;
        while (left <= right) {
            int mid = (left + right) / 2;
            if (nums[mid] == target) {
                return mid;
            } else {
                if (nums[mid] > target) {
                    right = mid - 1;
                } else {
                    left = mid + 1;
                }
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        Leetcode_704 l = new Leetcode_704();
        System.out.println(l.search(new int[]{-1, 0, 3, 5, 9, 12}, 9));
        System.out.println(l.search(new int[]{-1, 0, 3, 5, 9, 12, 13}, 9));
        System.out.println(l.search(new int[]{-1, 0, 3, 5, 9, 12}, 2));
    }
}



